import 'package:flutter/material.dart';
import 'package:flutter_snail/ui/style/snail_color.dart';
import 'package:flutter_snail/ui/style/snail_text_style.dart';

/// 底部导航栏
class SnailNavigationBar extends StatefulWidget {
  const SnailNavigationBar({
    Key? key,
    required this.currentIndex,
    required this.items,
    this.changed,
  }) : super(key: key);

  final int currentIndex;
  final List<BottomNavigationBarItem> items;
  final ValueChanged<int>? changed;

  @override
  State<SnailNavigationBar> createState() => _SnailNavigationBarState();
}

class _SnailNavigationBarState extends State<SnailNavigationBar> {
  late int currentIndex;

  @override
  void initState() {
    super.initState();
    currentIndex = widget.currentIndex;
  }

  @override
  Widget build(BuildContext context) {
    return BottomNavigationBar(
      items: widget.items,
      selectedItemColor: SnailColor.black70,
      unselectedItemColor: SnailColor.greyCD,
      currentIndex: currentIndex,
      showUnselectedLabels: true,
      onTap: (index) {
        setState(() => currentIndex = index);
        widget.changed?.call(index);
      },
    );
  }
}
